#include<stdio.h>
#include"buff_queue.h"


void buff_queue_init(struct buff_queue * buffer_queue)
{
	if(buffer_queue==NULL)
	{
		buffer_queue=(struct buff_queue*)malloc(sizeof(struct buff_queue));
	}
	buffer_queue->count=0;
	buffer_queue->head=NULL;
}

void buff_queue_add(struct buff_queue * buffer_queue,struct buff_queue_node *node)
{
	struct buff_queue_node * tail;
	struct buff_queue_node * current=buffer_queue->head;


	if(current==NULL)
	{
		log_info("add and buffer is empty");
		current=node;
		buffer_queue->head=node;

		buffer_queue->count++;
		printf("success add to queue %d\n",buffer_queue->count);

		return;
	}
	
	while(current->next!=NULL)
	{
		current=current->next;
	}
	
	current->next=node;
	buffer_queue->count++;
	
	printf("success add to queue %d\n",buffer_queue->count);
}


struct buff_queue_node* buff_queue_del(struct buff_queue * buffer_queue)
{
	struct buff_queue_node * current=buffer_queue->head;

	struct buff_queue_node * next;
	
	if(current==NULL)
	{
		log_error("del and buffer is empty");
		return NULL;
	}
	
	next=current->next;
	buffer_queue->head=next;

	buffer_queue->count--;
	printf("now you are in the buff_queue_del and the count are :%d\n",buffer_queue->count);
	return current;
}

int buff_queue_count(struct buff_queue *buffer_queue)
{
	return buffer_queue->count;
}


